package com.tianluo.tianluobookstore.advice;

import com.tianluo.tianluobookstore.enums.CommonCodeEnum;
import com.tianluo.tianluobookstore.exception.BizException;
import com.tianluo.tianluobookstore.response.BaseResponse;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice(annotations = RestController.class)
public class ControllerExceptionHandler {

    @ExceptionHandler(BizException.class)
    @ResponseBody
    public BaseResponse<Void> handler(BizException e) {
        System.out.println("进入业务异常"+e.getRetCode()+e.getRetMessage());
        return BaseResponse.fail(CommonCodeEnum.ERROR.getCode(), CommonCodeEnum.ERROR.getMessage());
    }
}
